<template>
  <!-- 最外层的div要去掉妈的 -->
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <!-- 头像区域 -->
        <div class="block">
          <el-avatar :size="45" :src="headImage"></el-avatar>
        </div>
        <span>卡包管理系统--商家</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 主题区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单区域 :是布尔值 -->
        <el-menu
          background-color="#333744"
          text-color="#fff"
          active-text-color="#409BFF"
          unique-opened
          :collapse="isCollapse"
          :collapse-transition="false"
          router
          :default-active="$route.path"
        >
          <!-- 一级菜单 -->
          <el-submenu
            :index="item.id + ''"
            v-for="(item, index) in menuList"
            :key="index"
          >
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconsObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{ item.authName }}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item
              :index="subItem.path"
              v-for="subItem in item.children"
              :key="subItem.id"
            >
              <!-- 二级菜单的模板区域 -->
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{ subItem.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
        
      </el-aside>
      <!-- 右侧 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "UserHome",
  methods: {
    logout() {
      // window.sessionStorage.clear();
      this.$message.success("您退出了");
      this.$router.push("/loginjudge");
    },
    // 点击按钮实现菜单的折叠和展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
  },
  created() {
    // this.getMenuList();
  },

  data() {
    return {
      // 头像地址
      headImage: require("../../../assets/img/headImg/default.png"),

      // 侧边栏列表
      menuList: [
        {
          id: 102,
          authName: "商家管理",
          children: [
            {
              id: 1021,
              authName: "公司信息",
              path: "/EnterpriseInfo",
            },
            {
              id: 1022,
              authName: "修改密码",
              path: "/ModifyPassword",
            },
          ],
        },
        {
          id: 103,
          authName: "商务管理",
          children: [
            {
              id: 1031,
              authName: "会员卡管理",
              path: "/vipcard",
            },
            {
              id: 1032,
              authName: "优惠券管理 ",
              path: "/coupon",
            },
          ],
        },
        {
          id: 104,
          authName: "订单管理",
          children: [
            {
              id: 1041,
              authName: "订单信息",
              path: "/orderinfo",
            },
            {
              id: 1042,
              authName: "订单审核",
              path: "/ordercheck",
            },
          ],
        },
        {
          id: 105,
          authName: "财务管理",
          children: [
            {
              id: 1051,
              authName: "流水收入",
              path: "/income",
            },
          ],
        },
      ],
      iconsObj: {
        101: "iconfont icon-user",
        102: "iconfont icon-tijikongjian",
        103: "iconfont icon-shangpin",
        104: "iconfont icon-danju",
        105: "iconfont icon-baobiao",
      },
      isCollapse: false,
    };
  },
};
</script>

<style lang="less" scoped>
#logo-img {
  height: 50px;
  // width: 50px;
  border-radius: 50%;
}
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  > div {
    display: flex;
    align-items: center;
    margin-left: 15px;
  }
}
.el-aside {
  background-color: #333744;
  .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: #eaedf1;
}
.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  // 间距
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>